/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgBuff
    {
        private readonly Dictionary<int, CfgBuff> _dataMap;
        private readonly List<CfgBuff> _dataList;


        public TbCfgBuff(ByteBuf _buf)
        {
            //first read common data
            _TbCommonBuff _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonBuff(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgBuff>(size * 3 / 2);
            _dataList = new List<CfgBuff>(size);

            for (int i = 0; i < size; i++)
            {
                CfgBuff _v;
                _v = CfgBuff.DeserializeCfgBuff(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgBuff> DataMap => _dataMap;
        public IReadOnlyList<CfgBuff> DataList => _dataList;

        public CfgBuff Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgBuff] config not found,id:" + key.ToString());

            return null;
        }

        public CfgBuff GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "buff";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgBuff LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgBuff(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgBuff
    {
        private CfgBuff(ByteBuf _buf, _TbCommonBuff _commonData)
        {
            Id = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; Icon = _commonData._field0[dataIndex]; }
            Range = _buf.ReadInt();
            Duration = _buf.ReadInt();
            MaxNum = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; Tag = _commonData._field1[dataIndex]; }
            Group = _buf.ReadInt();
            Type = _buf.ReadInt();
            TypePriiority = _buf.ReadInt();
            AddType = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; Effect = _commonData._field2[dataIndex]; }
            DotType = _buf.ReadInt();
            DotExecute = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; Dot = _commonData._field3[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; EffectView = _commonData._field4[dataIndex]; }
            EffectLoop = _buf.ReadBool();
            EffectType = _buf.ReadInt();
            EffectDummy = _buf.ReadInt();

            PostInit();
        }

        internal static CfgBuff DeserializeCfgBuff(ByteBuf _buf, _TbCommonBuff _commonData)
        {
            return new CfgBuff(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 图片(Assets\Res\05_Images\Sprite\Icon_Buff)
        /// </summary>
        public string Icon { get; private set; }
        /// <summary>
        /// 范围
        /// </summary>
        public int Range { get; private set; }
        /// <summary>
        /// 持续时间
        /// </summary>
        public int Duration { get; private set; }
        /// <summary>
        /// 最大叠加数量
        /// </summary>
        public int MaxNum { get; private set; }
        /// <summary>
        /// 
        /// </summary>
        public IReadOnlyList<int> Tag { get; private set; }
        /// <summary>
        /// 组
        /// </summary>
        public int Group { get; private set; }
        /// <summary>
        /// 类型
        /// </summary>
        public int Type { get; private set; }
        /// <summary>
        /// 类型优先级-数字大优先
        /// </summary>
        public int TypePriiority { get; private set; }
        /// <summary>
        /// 添加方式 0叠加并刷新持续时间1叠加单独计时2覆盖3留旧的
        /// </summary>
        public int AddType { get; private set; }
        /// <summary>
        /// 效果
        /// </summary>
        public IReadOnlyList<int> Effect { get; private set; }
        /// <summary>
        /// Dot类型 0 伤害 1 治疗
        /// </summary>
        public int DotType { get; private set; }
        /// <summary>
        /// 0回合开始 1 回合结束 2行动开始 3行动结束
        /// </summary>
        public int DotExecute { get; private set; }
        /// <summary>
        /// Dot伤害 公式|伤害类型
        /// </summary>
        public IReadOnlyList<int> Dot { get; private set; }
        /// <summary>
        /// buff特效1
        /// </summary>
        public IReadOnlyList<string> EffectView { get; private set; }
        /// <summary>
        /// 特效是否循环
        /// </summary>
        public bool EffectLoop { get; private set; }
        /// <summary>
        /// 特效播放类型 1 骨骼跟随 2 骨骼跟随但不旋转 3 骨骼坐标
        /// </summary>
        public int EffectType { get; private set; }
        /// <summary>
        /// 特效骨骼挂点
        /// </summary>
        public int EffectDummy { get; private set; }

        /// <summary>
        /// Icon资源全路径
        /// </summary>
        public string Icon_fullPath => $"Res/05_Images/Sprite/Icon_Buff/{Icon}.png";

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonBuff
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field1 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field2 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field3 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<string>> _field4 { get; private set; }
        internal _TbCommonBuff(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field3 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0][]; _field4 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new string[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ string __v1; __v1 = _buf.ReadString(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
        }

    }
}
